訂閱期貨盤中tick v1版報價資訊,範例如下:
api.quote.subscribe(
api.Contracts.Futures.TXF['TXF202110'], #期貨Contract
quote_type = sj.constant.QuoteType.Tick, #報價類型為Tick
version = sj.constant.QuoteVersion.v1, #回傳資訊版本為v1
)
# 定義quote_callback,即回傳報價資訊時所要執行的動作
@api.on_tick_fop_v1()
def quote_callback(exchange:Exchange, tick:TickFOPv1):
print(f"Exchange: {exchange}, Tick: {tick}")
Event().wait() #盤中執行程式時,若看不到quote_callback的執行結果,請加入此行,讓程式進入等待狀態
Tick QuoteVersion.v1,quote_callback的執行結果
Exchange: TAIFEX, Tick: Tick(code='TXFJ1', datetime=datetime.datetime(2021, 9, 24, 11, 31, 3, 208000), open=Decimal('17191'), underlying_price=Decimal('17249.79'), bid_side_total_vol=44400, ask_side_total_vol=44529, avg_price=Decimal('17223.595502'), close=Decimal('17234'), high=Decimal('17275'), low=Decimal('17170'), amount=Decimal('34468'), total_amount=Decimal('1208510802'), volume=2, total_volume=70166, tick_type=1, chg_type=2, price_chg=Decimal('154'), pct_chg=Decimal('0.901639'), simtrade=0)
Tick QuoteVersion.v1的報價內容說明
屬性 | 值 | 說明 |
---|---|---|
code | 'TXFJ1' | 期貨代碼 |
datetime | datetime.datetime(2021, 9, 24, 11, 31, 3, 208000) | 時間 |
open | Decimal('17191') | 開盤 |
underlying_price | Decimal('17249.79') | 標的物價格 |
bid_side_total_vol | 44400 | 買盤成交總量 |
ask_side_total_vol | 44529 | 賣盤成交總量 |
avg_price | Decimal('17223.595502') | 均價 |
close | Decimal('17234') | 成交價 |
high | Decimal('17275') | 最高 |
low | Decimal('17170') | 最低 |
amount | Decimal('34468') | 成交金額 |
total_amount | Decimal('1208510802') | 總成交金額 |
volume | 2 | 成交量 |
total_volume | 70166 | 總成交量 |
tick_type | 1 | tick類型 |
chg_type | 2 | 變動類型 |
price_chg | Decimal('154') | 價格變動 |
pct_chg | Decimal('0.901639') | 變動百分比 |
simtrade | '2330' | 是否為試撮 |
訂閱期貨盤中tick v0版報價資訊,範例如下:
api.quote.subscribe(
api.Contracts.Futures.TXF['TXF202110'], #期貨Contract
quote_type = sj.constant.QuoteType.Tick, #報價類型為Tick
version = sj.constant.QuoteVersion.v0, #回傳資訊版本為v0
)
# 定義quote_callback,即回傳報價資訊時所要執行的動作
@api.quote.on_quote
def quote_callback(topic: str, quote: dict):
print(f"Topic: {topic}, Quote: {quote}")
Event().wait()
Tick QuoteVersion.v0,quote_callback的執行結果
L/TFE/TXFJ1 {'Amount': [17233.0], 'AmountSum': [1213025639.0], 'AvgPrice': [17223.62752], 'Close': [17233.0], 'Code': 'TXFJ1', 'Date': '2021/09/24', 'DiffPrice': [153.0], 'DiffRate': [0.895785], 'DiffType': [2], 'High': [17275.0], 'Low': [17170.0], 'Open': 17191.0, 'TargetKindPrice': 17244.35, 'TickType': [0], 'Time': '11:34:06.678000', 'TradeAskVolSum': 44684, 'TradeBidVolSum': 44596, 'VolSum': [70428], 'Volume': [1]}
L/TFE/TXFJ1 {'Amount': [17234.0], 'AmountSum': [1213042873.0], 'AvgPrice': [17223.627668], 'Close': [17234.0], 'Code': 'TXFJ1', 'Date': '2021/09/24', 'DiffPrice': [154.0], 'DiffRate': [0.901639], 'DiffType': [2],
'High': [17275.0], 'Low': [17170.0], 'Open': 17191.0, 'TargetKindPrice': 17244.35, 'TickType': [1], 'Time': '11:34:09.279000', 'TradeAskVolSum': 44685, 'TradeBidVolSum': 44598, 'VolSum': [70429], 'Volume': [1]}
Tick QuoteVersion.v0的報價內容說明
屬性 | 值 | 說明 |
---|---|---|
Amount | [17233.0] | 成交金額(註) |
AmountSum | [1213025639.0] | 總成交金額(註) |
AvgPrice | [17223.62752] | 均價 |
Close | [17233.0] | 成交價 |
Code | 'TXFJ1' | 期貨代碼 |
Date | '2021/09/24' | 日期 |
DiffPrice | [153.0] | 差異價(漲跌) |
DiffRate | [0.895785] | 差異比例 |
DiffType | [2] | 差異類型 |
High | [17275.0] | 最高 |
Low | [17170.0] | 最低 |
Open | 17191.0 | 開盤 |
TargetKindPrice | 17244.35 | 標的物價格 |
TickType | [1] | Tick類型 |
Time | '11:34:09.279000' | 時間 |
TradeAskVolSum | 44685 | 賣盤成交總量 |
TradeBidVolSum | 44598 | 買盤成交總量 |
VolSum | [70429] | 總成交量 |
Volume | [1] | 成交量 |
期貨雖然也有成交價格,但跟個股不同的是期貨保證金是固定的,以小台指期為例,買進一口小台指期貨,不管你的成交價格(點)是多少,保證金都是46,000。所以雖然在回傳的報價資訊中也有Amount跟AmountSum,但實際上期貨是沒有在計算成交金額
訂閱期貨盤中bidask v1版報價資訊,範例如下:
api.quote.subscribe(
api.Contracts.Futures.TXF['TXF202110'], #期貨Contract
quote_type = sj.constant.QuoteType.BidAsk, #報價類型為BidAsk
version = sj.constant.QuoteVersion.v1 #回傳資訊版本為v1
)
@api.on_bidask_fop_v1()
def quote_callback(exchange:Exchange, bidask:BidAskFOPv1):
print(f"Exchange: {exchange}, BidAsk: {bidask}")
Event().wait()
BidAsk QuoteVersion.v1,quote_callback的執行結果
Exchange: TAIFEX, BidAsk: BidAsk(code='TXFJ1', datetime=datetime.datetime(2021, 9, 24, 11, 37, 20, 698000), bid_total_vol=109, ask_total_vol=90, bid_price=[Decimal('17232'), Decimal('17231'), Decimal('17230'), Decimal('17229'), Decimal('17228')], bid_volume=[14, 19, 17, 26, 33], diff_bid_vol=[-1, 0, 0, 0, 0], ask_price=[Decimal('17234'), Decimal('17235'), Decimal('17236'), Decimal('17237'), Decimal('17238')], ask_volume=[3, 15, 16, 20, 36], diff_ask_vol=[2, 0, 0, 0, 1], first_derived_bid_price=Decimal('17230'), first_derived_ask_price=Decimal('17237'), first_derived_bid_vol=5, first_derived_ask_vol=1, underlying_price=Decimal('17243.26'), simtrade=0)
BidAsk QuoteVersion.v1的報價內容說明
屬性 | 值 | 說明 |
---|---|---|
code | 'TXFJ1' | 期貨代碼 |
datetime | datetime.datetime(2021, 9, 24, 11, 37, 20, 698000) | 時間 |
bid_total_vol | 109 | 委買總量 |
ask_total_vol | 90 | 委賣總量 |
bid_price | [Decimal('17232'), Decimal('17231'), Decimal('17230'), Decimal('17229'), Decimal('17228')] | 委買價 |
bid_volume | [14, 19, 17, 26, 33] | 委買量 |
diff_bid_vol | [-1, 0, 0, 0, 0] | 委買量差異 |
ask_price | [Decimal('17234'), Decimal('17235'), Decimal('17236'), Decimal('17237'), Decimal('17238')] | 委賣價 |
ask_volume | [3, 15, 16, 20, 36] | 委賣量 |
diff_ask_vol | [2, 0, 0, 0, 1] | 委賣量差異 |
first_derived_bid_price | Decimal('17230') | 衍生一檔買價 |
first_derived_ask_price | Decimal('17237') | 衍生一檔賣價 |
first_derived_bid_vol | 5 | 衍生一檔買量 |
first_derived_ask_vol | 1 | 衍生一檔賣量 |
underlying_price | Decimal('17243.26') | 標的物價格 |
simtrade | 0 | 是否為試撮 |
訂閱期貨盤中bidask v0版報價資訊,範例如下:
api.quote.subscribe(
api.Contracts.Futures.TXF['TXF202110'], #期貨Contract
quote_type = sj.constant.QuoteType.BidAsk, #報價類型為BidAsk
version = sj.constant.QuoteVersion.v0 #回傳資訊版本為v0
)
@api.quote.on_quote
def quote_callback(topic: str, quote: dict):
print(f"Topic: {topic}, Quote: {quote}")
Event().wait()
BidAsk QuoteVersion.v1,quote_callback的執行結果
Topic: Q/TFE/TXFJ1, Quote: {'AskPrice': [17229.0, 17230.0, 17231.0, 17232.0, 17233.0], 'AskVolSum': 64, 'AskVolume': [2, 15, 17, 14, 16], 'BidPrice': [17228.0, 17227.0, 17226.0, 17225.0, 17224.0], 'BidVolSum': 106, 'BidVolume': [3, 18, 20, 37, 28], 'Code': 'TXFJ1', 'Date': '2021/09/24', 'DiffAskVol': [-4, -1, 0, 0, 0], 'DiffAskVolSum': 0, 'DiffBidVol': [-2, 4, 0, 0, 0], 'DiffBidVolSum': 0, 'FirstDerivedAskPrice': 17231.0,
'FirstDerivedAskVolume': 1, 'FirstDerivedBidPrice': 17225.0, 'FirstDerivedBidVolume': 1, 'TargetKindPrice': 17244.94, 'Time': '11:40:26.948000'}
BidAsk QuoteVersion.v0的報價內容說明
屬性 | 值 | 說明 |
---|---|---|
AskPrice | [17229.0, 17230.0, 17231.0, 17232.0, 17233.0] | 委賣價 |
AskVolSum | 64 | 委賣總量 |
AskVolume | [2, 15, 17, 14, 16] | 委賣量 |
BidPrice | [17228.0, 17227.0, 17226.0, 17225.0, 17224.0] | 委買價 |
BidVolSum | 106 | 委買總量 |
BidVolume | [3, 18, 20, 37, 28] | 委買量 |
Code | 'TXFJ1' | 期貨代碼 |
Date | '2021/09/24' | 日期 |
DiffAskVol | [-4, -1, 0, 0, 0] | 委賣量差異 |
DiffAskVolSum | 0 | 委賣量差異? |
DiffBidVol | [-2, 4, 0, 0, 0] | 委賣量差異 |
DiffBidVolSum | 0 | 委賣量差異? |
FirstDerivedAskPrice | 17231.0 | 衍生一檔賣價 |
FirstDerivedAskVolume | 1 | 衍生一檔賣量 |
FirstDerivedBidPrice | 17225.0 | 衍生一檔買價 |
FirstDerivedBidVolume | 1 | 衍生一檔買量 |
TargetKindPrice | 17244.94 | 標的物價格 |
Time | '11:40:26.948000' | 時間 |
所謂的「衍生一檔」,也就是一般俗稱ROLL單或是轉倉單
詳細委託及成交機制,請參考期交所文件
http://www.taifex.com.tw/chinese/9/期貨商品跨月價差委託機制說明.ppt